import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

// 需要维护的状态
const state = {
  //环境对象
  currentEnv:{},
  env:{
    daily:{url:'http://uacc.daily.jv.fliggy.com',name:'日常环境'},
    prepub:{url:'http://uacc.pre.jv.fliggy.com',name:'预发环境'},
    product:{url:'http://uacc.jv.fliggy.com',name:'线上环境'}
  },
  //是否显示菜单
  show: '隐藏',
  //前后台切换
  context:true,
  //根菜单树
  treeJson:'',
  //子菜单树
  menuJson:[],
  //当前节点信息
  currentNode:{},
  //所有的配置集合
  cfgMaps:[],
  //当前的配置集
  currentStructs:{},
  //当前用户信息
  currentUser:{}
};

const mutations = {
  edit(state, show) {
    state.show = show;
  },
  editContext(state, context) {
    state.context = context;
  },
  editTree(state, treeJson) {
    state.treeJson = treeJson;
  },
  editMenu(state, menuJson) {
    state.menuJson = menuJson;
  },
  editCurrentNode(state, currentNode) {
    state.currentNode = currentNode;
  },
  editCurrentEnv(state, currentEnv) {
    console.info('切换环境成功：'+currentEnv.name);
    state.currentEnv = currentEnv;
  },
  editCfgMaps(state, cfgMaps) {
    state.cfgMaps = cfgMaps;
  },
  editCurrentStructs(state, currentStructs) {
    state.currentStructs = currentStructs;
  },
  editCurrentUser(state, currentUser) {
    state.currentUser = currentUser;
  }
};
//store的计算属性，使用：
// 1.this.$store.getters.count;
// 2.mapGetters:计算属性中加入:...mapGetters(["count"]);
const getters = {
  getEnvUrl:function(state){
    return state.currentEnv.url;
  }
};

export default new Vuex.Store({
  state,
  mutations,
  getters
});
